package main

import (
	"bytes"
	"fmt"
	"strings"
)

func main()(){
	fmt.Println("hello world !")
	x := 1
	p := &x         // p, of type *int, points to x
	fmt.Println(*p) // "1"
	fmt.Printf("%v, %T \n", p, p)
	*p = 2          // equivalent to x = 2
	fmt.Println(x)  // "2"
	v := 1
	incr(&v)              // side effect: v is now 2
	fmt.Println(incr(&v)) // "3" (and v is 3)
	p2 := new(int)   // p, *int 类型, 指向匿名的 int 变量
	fmt.Println(*p2, p2) // "0"
	*p2 = 2          // 设置 int 匿名变量的值为 2
	fmt.Println(*p2) // "2"
	type customType int16
	var f customType = 100
	fmt.Printf("%T\n", f)
	sc := "qwerty"
	fmt.Println("-----", len(sc))
	flag := strings.Contains(sc, "qw")
	fmt.Println("---", flag)
	var buf bytes.Buffer
	buf.WriteByte('[')
	li := []int{1,3,3,4, 56}
	for i, v :=  range li{
		if i > 0 {
			buf.WriteString(", ")
			//fmt.Fprintf(&buf, "%d", v)
		}
		fmt.Fprintf(&buf, "%d", v)
	}
	buf.WriteByte(']')
	fmt.Println(buf.String())
	newLi := remove(li, 1)
	fmt.Println(newLi)
}


func incr(p *int) int {
	*p++ // 非常重要：只是增加p指向的变量的值，并不改变p指针！！！
	return *p
}

func remove(li []int, i int)[] int{
	li[i] = li[len(li) - 1]
	return li[:(len(li) - 1)]
}